<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// ------------------------------------------------------------------------

/**
 * Submit controller class
 *
 * Listing achievements
 *
 * @package		Achieve
 * @subpackage	Controllers
 * @category	Controllers
 * @author		Russ
 */
class Submit extends LoggedIn {
	
	/**
	 * Submission page
	 *
	 * @access	public
	 */
	public function index($achievementId = '')
	{	
		$this->load->helper(array('url'));
		$this->load->model(array('Achievements_model'));

		if($achievementId == '' || $this->Achievements_model->get_achievement_by_id($achievementId) == NULL)
		{
			redirect('/browse');
			return;
		}	
		
		$user = $this->session->all_userdata();
		
		if($this->Achievements_model->submission_achievement_exists($achievementId, $user['id']))
		{
			$this->session->set_flashdata('notice', 'You have already submitted this achievement');
			redirect('/browse');
			return;
		}
		
		if($this->Achievements_model->completed_achievement_exists($achievementId, $user['id']))
		{
			$this->session->set_flashdata('notice', 'You have already completed this achievement');
			redirect('/browse');
			return;
		}
		
		$achievement = $this->Achievements_model->get_achievement_by_id($achievementId);
		
        $this->data['title'] = "Achievement Submission";
		if($this->session->flashdata('notice') != '')
			$this->data['notice'] = $this->session->flashdata('notice');
		$this->parser->parse("submit/submit.tpl", $this->data);
	}
	
	/**
	 * Processes the achievement submission
	 *
	 * @access	public
	 */
	public function process()
	{	
		
	}
	
}
?>